using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Public_CheckDelivery : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Con"].ToString());
            con.Open();
            SqlCommand cmd = new SqlCommand(String.Format("select DeliveryNo, Weight, DateOfPosting, Name, DestinationAddress, CustID, Feetype.Fee, Status, ReceiveDate from Delivery, Service, Feetype where Delivery.ServiceID=Service.ServiceID and Delivery.FeeTypeID=Feetype.FeeTypeID and DeliveryNo={0} and CustID={1}", Int32.Parse(TextBox1.Text), Int32.Parse(TextBox2.Text)), con);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                lblDeliveryNo.Text = dr.GetInt32(0).ToString();
                lblWeight.Text = dr.GetDouble(1).ToString() + " kg";
                lblDOP.Text = dr.GetDateTime(2).ToString();
                lblService.Text = dr.GetString(3);
                lblDest.Text = dr.GetString(4);
                lblCust.Text = dr.GetInt32(5).ToString();
                lblFeetype.Text = dr.GetDecimal(6).ToString();
                bool stt = dr.GetBoolean(7);
                if (stt)
                    lblStatus.Text = "Sent";
                else
                    lblStatus.Text = "Pending";
                lblReceive.Text = "";
                if (!dr.IsDBNull(8))
                    lblReceive.Text = dr.GetDateTime(8).ToString();
                VisibleLabels();
                Label3.Visible = true;
                Label3.Font.Bold = false;
                Label3.Font.Italic = true;
                Label3.Font.Size = 12;
                Label3.ForeColor = System.Drawing.Color.Black;
                Label3.Text = "This is your delivery's status:";
            }
            else
            {
                InvisibleAndNullLabels();
                Label3.Visible = true;
                Label3.Font.Bold = true;
                Label3.Font.Italic = false;
                Label3.Font.Size = 20;
                Label3.ForeColor = System.Drawing.Color.Red;
                Label3.Text = "Not Found!";
            }
        }
        catch (Exception ex)
        {
            InvisibleAndNullLabels();
            Label3.Visible = true;
            Label3.Font.Bold = true;
            Label3.Font.Italic = false;
            Label3.Font.Size = 20;
            Label3.ForeColor = System.Drawing.Color.Red;
            Label3.Text = ex.Message;
        }
    }

    private void VisibleLabels()
    {
        Label3.Visible = true;
        Label12.Visible = true;
        Label13.Visible = true;
        Label14.Visible = true;
        Label15.Visible = true;
        Label16.Visible = true;
        Label17.Visible = true;
        Label18.Visible = true;
        Label19.Visible = true;
        Label20.Visible = true;
    }

    private void InvisibleAndNullLabels()
    {
        Label3.Visible = false;
        Label12.Visible = false;
        Label13.Visible = false;
        Label14.Visible = false;
        Label15.Visible = false;
        Label16.Visible = false;
        Label17.Visible = false;
        Label18.Visible = false;
        Label19.Visible = false;
        Label20.Visible = false;

        lblDeliveryNo.Text = "";
        lblWeight.Text = "";
        lblDOP.Text = "";
        lblService.Text = "";
        lblDest.Text = "";
        lblCust.Text = "";
        lblFeetype.Text = "";
        lblStatus.Text = "";
        lblReceive.Text = "";
    }
}
